#include <iostream>
#include <sstream>

template <typename T>

void mySort(T *arr, int len)
{
    if (len == 0 || arr == nullptr)
        return;

    for (int i = 0; i < len; i++)
    {
        int minIndex = i;
        for (int j = i + 1; j < len; j++)
        {
            if (arr[j] < arr[minIndex])
            {
                minIndex = j;
            }
        }
        if (minIndex != i)
        {
            T temp = arr[minIndex];
            arr[minIndex] = arr[i];
            arr[i] = temp;
        }
    }
}

template <typename T>
std::string toString(T *array, int len)
{
    std::ostringstream out;
    if (len == 0 || array == nullptr)
    {
        return "[]";
    }

    out << "[";
    for (int i = 0; i < len - 1; i++)
    {
        out << array[i] << ", ";
    }
    out << array[len - 1] << "]";
    return out.str();
}

int main(int argc, char const *argv[])
{
    
    int arr[] = {1, 3, 2, 4, 0, 1, 2, 6, 4, 0};
    int len = (sizeof(arr)) / (sizeof(int));
    std::cout << toString(arr, len) << std::endl;
    mySort(arr, len);
    std::cout << toString(arr, len) << std::endl;

    double arr2[] = {3.24, 432.324, 432.4, 432.9, 654.433, 3.92, 7.94, 0.0035, 9982.654};
    int len2 = sizeof(arr2) / sizeof(double);
    std::cout << toString(arr2, len2) << std::endl;
    mySort(arr2, len2);
    std::cout << toString(arr2, len2) << std::endl;

    return 0;
}
